package com.gjy.netty.ag.bio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-17 17:26:02
 */
public class TimeClient {

    private static final Logger logger = LoggerFactory.getLogger(TimeClient.class);

    private static Integer PORT = 8000;

    public static void main(String[] args) {

        if (args != null && args.length > 0) {
            try {
                PORT = Integer.parseInt(args[0]);
            } catch (Exception e) {
                PORT = 8000;
            }
        }

        try (Socket socket = new Socket("127.0.0.1", PORT);
             InputStreamReader isr = new InputStreamReader(socket.getInputStream());
             BufferedReader in = new BufferedReader(isr);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) {
            out.println("query time order");

            logger.info("send order 2 server succeed");
            String s = in.readLine();
            logger.info("now is: {}", s);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
